<script setup lang="ts" name="BomfCacheServiceIndex">
import { reactive } from "vue";
import { ElNotification } from "element-plus";
import {
  removeAllCache,
  removeCacheCodeList,
  removeBeanCache,
  removeCacheTreeList,
  removeOrgCache
} from "@/api/modules/org/bomf-cache";

const BomfCacheState = reactive({
  removeAllCacheLoading: false,
  onRemoveAllCache: () => {
    BomfCacheState.removeAllCacheLoading = true;
    removeAllCache().then(() => {
      ElNotification({ title: "成功", message: "刷新所有缓存成功", type: "success" });
      BomfCacheState.removeAllCacheLoading = false;
    });
  },

  rmoveCacheCodeListLoading: false,
  onRmoveCacheCodeList: () => {
    BomfCacheState.rmoveCacheCodeListLoading = true;
    removeCacheCodeList().then(() => {
      ElNotification({ title: "成功", message: "刷新数据字典缓存成功", type: "success" });
      BomfCacheState.rmoveCacheCodeListLoading = false;
    });
  },
  removeCacheTreeListLoading: false,
  onRemoveCacheTreeList: () => {
    BomfCacheState.removeCacheTreeListLoading = true;
    removeCacheTreeList().then(() => {
      ElNotification({ title: "成功", message: "刷新树缓存成功", type: "success" });
      BomfCacheState.removeCacheTreeListLoading = false;
    });
  },
  removeOrgCacheLoading: false,
  onRemoveOrgCache: () => {
    BomfCacheState.removeOrgCacheLoading = true;
    removeOrgCache().then(() => {
      ElNotification({ title: "成功", message: "刷新组织机构缓存成功", type: "success" });
      BomfCacheState.removeOrgCacheLoading = false;
    });
  },
  removeBeanCacheLoading: false,
  onRemoveBeanCache: () => {
    BomfCacheState.removeBeanCacheLoading = true;
    removeBeanCache().then(() => {
      ElNotification({ title: "成功", message: "刷新bean缓存成功", type: "success" });
      BomfCacheState.removeBeanCacheLoading = false;
    });
  }
});
</script>
<template>
  <div class="BomfCacheServiceIndex">
    <el-button type="primary" :loading="BomfCacheState.removeAllCacheLoading" @click="BomfCacheState.onRemoveAllCache">
      刷新所有缓存
    </el-button>
    <el-button type="success" :loading="BomfCacheState.rmoveCacheCodeListLoading" @click="BomfCacheState.onRmoveCacheCodeList">
      刷新数据字典
    </el-button>
    <el-button type="info" :loading="BomfCacheState.removeCacheTreeListLoading" @click="BomfCacheState.onRemoveCacheTreeList">
      刷新树
    </el-button>
    <el-button type="warning" :loading="BomfCacheState.removeOrgCacheLoading" @click="BomfCacheState.onRemoveOrgCache">
      刷新组织机构
    </el-button>
    <el-button type="danger" :loading="BomfCacheState.removeBeanCacheLoading" @click="BomfCacheState.onRemoveBeanCache">
      刷新bean缓存
    </el-button>
  </div>
</template>
